package com.datawale.vh.demo.work.util;

import org.apache.commons.codec.binary.Base64;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.UUID;

/**
 * @author huangtao
 * @time 2023/6/12
 * @description
 */
public class CommonUtil {

    /**
     * 获取uuid
     * @return
     */
    public static String getUUID(){
        String uid = UUID.randomUUID().toString();
        return uid;
    }

    /**
     * 文本转换成base64
     * @param filepath
     * @return
     */
    public static String fileToBase64(String filepath){
        InputStream in = null;
        byte[] data = null;
        try {
            in = Files.newInputStream(Paths.get(filepath));
            data = new byte[in.available()];
            in.read(data);
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Base64 base64 = new Base64();
        return base64.encodeToString(data);
    }

}
